#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
string s;
int n, q;
int main()
{
	cin >> n >> q;
	while (q--) {
		cin >> s;
		int ans = 1;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == 'R') ans *= 2;
			else ans = 2 * ans - 1;
		}
		cout << ans << endl;
	}
	return 0;
}